﻿using AutoMapper.Internal.Mappers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace Himp.Platform.Dc
{
    /// <summary>
    /// 药品给药途径字典服务
    /// </summary>
    public class DrugMedcWayService : CrudAppService<DrugMedcWay, DrugMedcWayDto, Guid, DrugMedcWayInput, DrugMedcWayCreateDto, DrugMedcWayUpdateDto>
    {
        private IRepository<DrugMedcWay, Guid> _drugMedcWayDictRepository;

        public DrugMedcWayService(IRepository<DrugMedcWay, Guid> drugMedcWayDictRepository) : base(drugMedcWayDictRepository)
        {
            _drugMedcWayDictRepository = drugMedcWayDictRepository;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public override async Task<PagedResultDto<DrugMedcWayDto>> GetListAsync(DrugMedcWayInput input)
        {
            var iQuery = await _drugMedcWayDictRepository.GetQueryableAsync();

            if (input.SkipCount == 0)
            {
                var itemsDto = ObjectMapper.Map<List<DrugMedcWay>, List<DrugMedcWayDto>>(iQuery.ToList());

                return new PagedResultDto<DrugMedcWayDto>(itemsDto.Count, itemsDto);
            }
            else
            {
                var totalCount = iQuery.Count();
                var items = iQuery.Page(input.SkipCount, input.MaxResultCount);
                var itemsDto = ObjectMapper.Map<List<DrugMedcWay>, List<DrugMedcWayDto>>(items.ToList());

                return new PagedResultDto<DrugMedcWayDto>(totalCount, itemsDto);
            }
        }
    }
}
